﻿Public Class viewCustomers
    Dim item As ListViewItem
    Sub listdata()
        If Not rs.EOF Then
            ListView1.Items.Clear()
            rs.MoveFirst()
            Do While Not rs.EOF
                item = ListView1.Items.Add(rs.Fields("CustomerNo").Value)
                item.SubItems.Add(rs.Fields("Name1").Value)
                item.SubItems.Add(rs.Fields("Address").Value)
                item.SubItems.Add(rs.Fields("City").Value)
                rs.MoveNext()

            Loop
        Else
            ListView1.Items.Clear()

        End If
        rs.Close()
        rs = Nothing

    End Sub

    Private Sub viewCustomers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Module1.connect()
        rs = New ADODB.Recordset
        rs.Open("select * from customers", cn, 3, 2)
        Me.listdata()
        RadioButton1.Checked = True

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        rs = New ADODB.Recordset
        rs.Open("SELECT * from customers where name1 = '" & receiptTransaction.TextBox1.Text & "'", cn, 3, 2)
        If Not rs.EOF Then
            receiptTransaction.TextBox4.Text = rs.Fields("customerno").Value
        End If
        rs.Close()
        rs = Nothing
        receiptTransaction.Button1.Enabled = False
        Me.Close()

    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

        receiptTransaction.TextBox4.Text = ListView1.FocusedItem.Text
    End Sub



   

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        If RadioButton1.Checked Then
            rs = New ADODB.Recordset
            rs.Open("SELECT * from customers where Name1  like '%" & TextBox1.Text & "%'", cn, 3, 2)
            Me.listdata()
        Else
            If RadioButton2.Checked Then
                rs = New ADODB.Recordset
                rs.Open("SELECT * from customers where address  like '%" & TextBox1.Text & "%'", cn, 3, 2)
                Me.listdata()

            Else
                If RadioButton3.Checked Then
                    rs = New ADODB.Recordset
                    rs.Open("SELECT * from customers where city  like '%" & TextBox1.Text & "%'", cn, 3, 2)
                    Me.listdata()
                End If
            End If
        End If

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        TextBox1.Text = ""
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        TextBox1.Text = ""
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        TextBox1.Text = ""
    End Sub

    Private Sub viewCustomers_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

    End Sub
End Class